package com.enzoism.springboot.fastjson.controller;

import com.enzoism.springboot.fastjson.model.Scores;
import com.enzoism.springboot.fastjson.result.RequestResult;
import com.enzoism.springboot.fastjson.service.ScoresService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Controller直接调用service层代码
 */
@RequestMapping("service")
@RestController
public class ScoresServiceController {
    @Resource
    public ScoresService scoresService;

    /**
     * 列表
     */
    @GetMapping("list")
    public RequestResult getScoreList() {
        List<Scores> scoreList = scoresService.selectDataList();
        return RequestResult.success(scoreList);
    }

    /**
     * 详情
     */
    @GetMapping("detail/{id}")
    public RequestResult getScoreDetail(@PathVariable Integer id) {
        Scores scores = scoresService.selectByPrimaryKey(id);
        return RequestResult.success(scores);
    }

    /**
     * 更新
     */
    @PostMapping("update")
    public RequestResult updateByPrimaryKey(@RequestBody Scores scores) {
        Scores updateScores = scoresService.updateByPrimaryKey(scores);
        return RequestResult.success(updateScores);
    }

    /**
     * 删除重插
     */
    @PostMapping("reinsert")
    public RequestResult reinsertByPrimaryKey(@RequestBody Scores scores) {
        Scores reinsertScore = scoresService.reinsertByPrimaryKey(scores);
        return RequestResult.success(reinsertScore);
    }

    /**
     * 删除重插
     */
    @PostMapping("reinsert/runtime")
    public RequestResult reinsertByPrimaryKeyRuntimeException(@RequestBody Scores scores) {
        Scores reinsertScore = scoresService.reinsertByPrimaryKeyRuntimeException(scores);
        return RequestResult.success(reinsertScore);
    }

    /**
     * 删除重插
     */
    @PostMapping("reinsert/sql")
    public RequestResult reinsertByPrimaryKeySQLException(@RequestBody Scores scores) {
        Scores reinsertScore = scoresService.reinsertByPrimaryKeySQLException(scores);
        return RequestResult.success(reinsertScore);
    }
}
